"""
Case Type   : 系统表
Case Name   : 测试系统表GS_ASP字段与数据类型是否正确
Create At   :2024/07/08
Owner       :sungang14
Description : 
    1.查看系统表GS_ASP的表结构
        \d GS_ASP
    2.该表字段与对应字段数据类型是否正确
Expect      : 
    1.查看系统表GS_ASP表结构成功
    2.该表字段与字段数据类型对应正确
History     : 
"""

import sys
import os
import unittest
from yat.test import Node
from yat.test import macro

sys.path.append(sys.path[0] + "/../")
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH


class IndexFileDamaged(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'-----{os.path.basename(__file__)} start-----')
        self.logger.info('----------------this is setup-----------------------')
        self.userNode = Node('dbuser')
        self.DB_ENV_PATH = macro.DB_ENV_PATH
        self.DB_INSTANCE_PATH = macro.DB_INSTANCE_PATH
        self.com = Common()
        self.comsh = CommonSH('dbuser')
        self.expect_result_dict = {
            'Column': ['sampleid', 'sample_time', 'need_flush_sample', 'databaseid', 'thread_id', 'sessionid',
                       'start_time', 'event', 'lwtid',
                       'psessionid', 'tlevel', 'smpid', 'userid', 'application_name', 'client_addr', 'client_hostname',
                       'client_port',
                       'query_id', 'unique_query_id', 'user_id', 'cn_id', 'unique_query', 'locktag', 'lockmode',
                       'block_sessionid', 'wait_status', 'global_sessionid', 'xact_start_time', 'query_start_time',
                       'state'],
            'Type': ['bigint', 'timestamp with time zone', 'boolean', 'oid', 'bigint', 'bigint',
                     'timestamp with time zone', 'text', 'integer', 'bigint', 'integer',
                     'integer', 'oid', 'text', 'inet', 'text', 'integer', 'bigint', 'bigint', 'oid', 'integer', 'text',
                     'text', 'text', 'bigint', 'text', 'text',
                     'timestamp with time zone', 'timestamp with time zone', 'text']
        }

    def test_Index_file_damaged(self):
        self.logger.info('----------------------------查看表结构-----------------------------')
        msg = self.comsh.execut_db_sql('\d GS_ASP')
        self.logger.info(msg)
        result_dict = self.com.format_sql_result(msg)
        self.logger.info(result_dict)
        del result_dict['Modifiers']
        self.assertDictEqual(self.expect_result_dict, result_dict)

    def tearDown(self):
        self.logger.info('----------------this is tearDown-----------------------')
        # 无须清理环境
        self.logger.info(f'-----{os.path.basename(__file__)} end-----')
